module AboutYou
  module SDK
    module Model
      ###
      # This class represents a category tree model
      ###
      class CategoryTree
        # instance of AboutYou::SDK::Model::CategoryManager::DefaultCategoryManager
        attr_accessor :category_manager

        ###
        # Constructor for the AboutYou::SDK::Model::CategoryTree class
        #
        # * *Args* :
        #   - +cat_manager+ -> The category manager
        #
        # * *Returns* :
        #   - an instance of AboutYou::SDK::Model::CategoryTree
        ###
        def initialize(cat_manager)
          self.category_manager = cat_manager

          self
        end

        ###
        # This method is used for getting the root categories of the tree
        #
        # * *Args* :
        #   - +act_only+ -> boolean controlling whether the result should only contain active categories or not
        #
        # * *Returns* :
        #   - a Hash containing pairs of category_id => instance of AboutYou::SDK::Model::Category
        ###
        def categories(act_only = AboutYou::SDK::Model::Category::ACTIVE_ONLY)
          category_manager.category_tree(act_only)
        end

        ###
        # This method counts all active root categories
        #
        # * *Returns* :
        #   - Integer count of active root categories
        ###
        def count
          categories(true).count
        end
      end
    end
  end
end
